package hikari.persistence.propertieseditor.editors;

import java.util.HashMap;
import java.util.Map;

/**
 * @author sad
 */
public class IEditorRegistry {

    private static Map<String, Class> registry = new HashMap<>();
    private static Map<Class, String> registryClassToName = new HashMap<>();

    static {
        add("java.lang.Integer", IntegerPropertyEditor.class);
        add("int", IntegerPropertyEditor.class);
        add("java.lang.String", StringPropertyEditor.class);
        add("java.lang.Boolean", BooleanPropertyEditor.class);
        add("boolean", BooleanPropertyEditor.class);
        add("java.lang.Float", FloatPropertyEditor.class);
        add("float", FloatPropertyEditor.class);
    }

    public static void add(String type, Class editor) {
        registry.put(type, editor);
    }

    @SuppressWarnings("unchecked")
    public static Class<IPropertyEditor> getEditor(String type) {
        return registry.get(type);
    }
    
    public static String getType(Class<? extends IPropertyEditor>clazz) {
        return registryClassToName.get(clazz);
    }
}
